package launcher;

import interfaces.AuthDialog;
import interfaces.MainFrame;
import interfaces.MyConfirmDialog;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import services.User;

public class Launcher {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		User showDialog = AuthDialog.showDialog();
		if(showDialog == null) {
			System.exit(0);
		}
		MainFrame mainFrame = new MainFrame(showDialog);
		mainFrame.setVisible(true);
		mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		mainFrame.addWindowListener( new WindowAdapter()
		{
		    public void windowClosing(WindowEvent e)
		    {
		        JFrame frame = (JFrame)e.getSource();
		        int result = MyConfirmDialog.showDialog("Вы действительно хотите выйти?", "Предупреждение",
		        		JOptionPane.WARNING_MESSAGE, null);
		        if (result == JOptionPane.YES_OPTION) {
		            frame.dispose();
		        	System.exit(0);
		        }
		    }
		});
	}
}
